package listener;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * Class that creates keyboard listeners and makes input information
 * available to the gamecontroller.
 * @author Jei
 *
 */
public class KeyboardListener extends KeyAdapter {

    private KeyEvent myLastKeyPressed;

    /**
     * Constructor that sets last key pressed value to null;
     */
    public KeyboardListener () {
        myLastKeyPressed = null;
    }

    @Override
    public synchronized void keyPressed (KeyEvent e) {
        myLastKeyPressed = e;
    }

    @Override
    public synchronized void keyReleased (KeyEvent e) {
        myLastKeyPressed = null;
    }

    /**
     * Returns the KeyEvent associated with the last key pressed by the
     * user. 
     * @return KeyEvent myLastKeyPressed
     */
    public KeyEvent getLastKeyPressed () {
        return myLastKeyPressed;
    }
}
